import {defineStore} from "pinia";
import {ref} from "vue";

export const uploadInfoStore = defineStore('upload', () => {
    const fileList = ref([])
    const parses = ref([])
    const incompleteFileList = ref([])

    const setIncompleteFileList = (fileList) => {
        incompleteFileList.value = fileList
        // 添加进度
        for (let i = 0; i < incompleteFileList.value.length; i++) {
            incompleteFileList.value[i].progress = (incompleteFileList.value[i].count / incompleteFileList.value[i].totalShards).toFixed(2)
        }
    }

    const setFileList = (fileList) => {
        fileList.value = fileList
    }

    const addFileList = (file) => {
        fileList.value.push(file)
    }

    const addParses = (file) => {
        parses.value.push(file)
    }

    const clearSuccess = () => {
        fileList.value = fileList.value.filter(item => item.percentage < 100)
    }

    return {fileList, parses, addFileList, addParses,clearSuccess,setFileList,setIncompleteFileList}
})